package com.example.demo.service;

import com.example.demo.entity.InstrumentCollection;
import com.example.demo.mapper.InstrumentCollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InstrumentCollectionImpl implements InstrumentCollectionService {

    @Autowired
    private InstrumentCollectionMapper instrumentCollectionMapper;

    @Override
    public boolean addCollection(InstrumentCollection instrumentCollection) {
        return instrumentCollectionMapper.addCollection(instrumentCollection) > 0;
    }

    // 删除收藏
    @Override
    public boolean deleteCollection(InstrumentCollection instrumentCollection) {
        return instrumentCollectionMapper.deleteCollection(instrumentCollection.getUser_id(), instrumentCollection.getInstrument_id()) > 0;
    }

    @Override
    public List<InstrumentCollection> getCollectionsByUserId(Integer userId) {
        return instrumentCollectionMapper.getCollectionsByUserId(userId);
    }

    @Override
    public boolean isCollected(Integer userId, Integer instrumentId) {
        return instrumentCollectionMapper.checkIfCollected(userId, instrumentId) > 0;
    }
}
